package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"regexp"
)

func file_get_contents(url string) string {
	r, e := http.Get(url)
	if e != nil {
		fmt.Println("http get error", e)
		return ""
	}
	defer r.Body.Close()
	c, e := ioutil.ReadAll(r.Body)
	if e != nil {
		fmt.Println("read error", e)
		return ""
	}
	return string(c)
}
func get_title(url string, c chan string) {
	html := file_get_contents(url)
	r := regexp.MustCompile(`<title>([^<].+?)<\/title>`)
	rs := r.FindStringSubmatch(html)
	c <- rs[1]
}
func main() {
	u := []string{}
	//fmt.Printf("%T",u)
	u = append(u, "https://news.sina.com.cn/w/2021-03-05/doc-ikftpnnz2409041.shtml")
	u = append(u, "https://news.sina.com.cn/w/2021-03-05/doc-ikftpnnz2349422.shtml")
	u = append(u, "https://news.sina.com.cn/w/2021-11-18/doc-iktzscyy6216667.shtml")
	u = append(u, "https://news.sina.com.cn/w/2021-11-18/doc-iktzqtyu7984044.shtml")
	u = append(u, "https://news.sina.com.cn/w/2021-11-18/doc-iktzqtyu7980358.shtml")
	u = append(u, "https://news.sina.com.cn/w/2021-11-18/doc-iktzqtyu7981390.shtml")

	l := len(u)
	c := make(chan string)
	for i := 0; i < l; i++ {
		go get_title(u[i], c)
	}
	for i := 0; i < l; i++ {
		fmt.Println(<-c)
	}
}
